/**
 * 描述: 入口文件
 * 作者: Jack Chen
 * 日期: 2020-06-12
*/

const bodyParser = require('body-parser'); // 引入body-parser模块
const express = require('express'); // 引入express模块
const cors = require('cors'); // 引入cors模块
const routes = require('./routes'); //导入自定义路由文件，创建模块化路由
const app = express();

app.use(bodyParser.json()); // 解析json数据格式
app.use(bodyParser.urlencoded({extended: true})); // 解析form表单提交的数据application/x-www-form-urlencoded

app.use(cors()); // 注入cors模块解决跨域


// app.use('/', routes);

const { querySql, queryOne } = require('./utils/index.js');
app.use('/test/:id',(req,res,next)=>{	
	//查询数据
	let query = `select * from sys_task`;
	let insert = `insert into sys_task (title,content,status,is_major,gmt_create,gmt_expire) values 
		("插入","插入新数据","2",0,null,"2021-07-21T08:00:00.000Z")`
	// queryOne(insert).then(data =>{
	querySql(query).then(data =>{
		console.log(data);
		res.json({
			"code":1,
			"count":data.length?data.length:0,
			"data":data,
			"msg":"success",
		})
	})
})


app.listen(8088, () => { // 监听8088端口
	console.log('服务已启动 http://localhost:8088');
})